"""Example client for BigServer - demonstrates how to use the OpenAI-compatible API"""
import openai
import requests
import json


def test_bigserver_api():
    \"\"\"Test the BigServer API with a simple request.\"\"\"
    
    # Method 1: Using OpenAI-compatible client
    print(\"Testing with OpenAI-compatible client...\")
    try:
        # Configure the client to point to BigServer
        openai.base_url = \"http://localhost:8000/v1\"
        openai.api_key = \"dummy-key\"  # BigServer doesn't require a real API key

        # Chat completion
        response = openai.ChatCompletion.create(
            model=\"microsoft/DialoGPT-medium\",  # Replace with actual model
            messages=[
                {\"role\": \"user\", \"content\": \"Hello, how are you?\"}
            ],
            max_tokens=50,
            temperature=0.7
        )
        
        print(f\"Chat completion response: {response.choices[0].message.content}\")
    except Exception as e:
        print(f\"Error with OpenAI client: {e}\")
    
    print(\"\\n\" + \"=\"*50 + \"\\n\")
    
    # Method 2: Using direct HTTP requests
    print(\"Testing with direct HTTP requests...\")
    try:
        url = \"http://localhost:8000/v1/chat/completions\"
        
        headers = {
            \"Content-Type\": \"application/json\"
        }
        
        payload = {
            \"model\": \"microsoft/DialoGPT-medium\",  # Replace with actual model
            \"messages\": [
                {\"role\": \"user\", \"content\": \"Hello, how are you?\"}
            ],
            \"max_tokens\": 50,
            \"temperature\": 0.7
        }
        
        response = requests.post(url, headers=headers, data=json.dumps(payload))
        
        if response.status_code == 200:
            result = response.json()
            print(f\"Direct HTTP response: {result['choices'][0]['message']['content']}\")
        else:
            print(f\"HTTP request failed with status {response.status_code}: {response.text}\")
    except Exception as e:
        print(f\"Error with direct HTTP request: {e}\")


if __name__ == \"__main__\":
    print(\"BigServer API Test Client\")
    print(\"Make sure BigServer is running on http://localhost:8000 before running this test\")
    print(\"Start the server with: python api.py\")
    print()
    
    test_bigserver_api()